
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            var adid = Config.adid;
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'family/members/index' + location.search,
                    add_url: 'family/members/add',
                    edit_url: 'family/members/edit',
                    del_url: 'family/members/del',
                    multi_url: 'family/members/multi',
                    import_url: 'family/members/import',
                    table: 'family_members',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: 'ID' },
                        { field: 'username', title: __('Username') },
                        { field: 'nickname', title: __('Nickname') },
                        { field: 'groups_text', title: __('Group'), operate: false, formatter: Table.api.formatter.label },
                        { field: 'email', title: __('Email') },
                        { field: 'mobile', title: __('Mobile') },
                        { field: 'status', title: __("Status"), searchList: { "normal": __('Normal'), "hidden": __('Hidden') }, formatter: Table.api.formatter.status },
                        {
                            field: 'operate',
                            width: "150px",
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    title: __('发送Ajax'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    icon: 'fa fa-trash',
                                    text:"退出家庭",
                                    confirm: '确认退出家庭吗？',
                                    url: 'family/members/tuichu',
                                    visible: function (e) {
                                        if (adid != e.id)
                                            return !0
                                    },
                                    success: function (data, ret) {
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        // //如果需要阻止成功提示，则必须使用return false;
                                        // //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons,
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});








